﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/m.master" %>


<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/enterpriseLayout/makePlan.css" rel="stylesheet" />
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/css/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
    <style>
        .condition {
            padding: 5px;
            border-bottom: 1px solid #ccc;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container"></div>

            <div class="condition">

                <label>年月</label>
                <input name="search-date" placeholder="年月" class="form-control layer-date  input-w110" id="search-date" />
                <label>维度</label>
                <div class=" i-checks">
                    <label>
                        <input type="radio" class="Dimension" name="Dimension" checked="checked" value="A" data-fieldname="商品层" />
                        商品层</label>
                </div>
                <div class=" i-checks">
                    <label>
                        <input type="radio" class="Dimension" name="Dimension" value="B" data-fieldname="品类" />
                        品类</label>
                </div>

            </div>
            <div class="right-content-box">
                <div class="ibox-content">
                    <div style="overflow: auto; background: #fff;" class="tb-body">
                        <div class="tb-head-container">
                            <div class="ibox-content">
                                <table class="loadTable">
                                    <thead></thead>
                                </table>
                            </div>
                        </div>
                        <div class="tb-body-container">
                            <div class="ibox-content">
                                <table class="loadTable">
                                  <%--  <thead></thead>--%>
                                    <tbody class="loadList"></tbody>
                                </table>
                            </div>
                        </div>


                    </div>

                </div>
            </div>




        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">

    <script src="../assets/js/plugins/linq/jquery.linq.min.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/linq/jquery.linq.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script>


        $(document).ready(function () {
            //自动收缩左边菜单栏
            commonUtil.autoLeftWidth();
            var ModuleID = Y.getUrlParam("ModuleID");
            //获取浏览器类型
            var sUserAgent = navigator.userAgent.toLowerCase();
            //获取按钮
            commonUtil.loadBtnList(ModuleID, function () { });
            //计算容器大小
            var calcContainer = function () {
                //计算step容器高度
                $('.wizard .content').height(
                     $('.right-side').height() - 5);

                $('.tb-body-container').height($('.right-side').height() -
                     $('.condition').outerHeight() - $('.tb-head-container').outerHeight() - (sUserAgent.indexOf('chrome') > -1 ? 75 : 84));

                //表格body宽
                var _w = $(".tb-head-container .loadTable").width()
                $(".tb-body-container").width(_w + 1);
                // $(".tb-body-container").width($(".tb-head-container .loadTable").width());
            }

            //处理表格兼容
            var sUserAgent = navigator.userAgent.toLowerCase();
            if (sUserAgent.indexOf('chrome') == -1) {
                $('.tb-head-container').css({ 'paddingRight': '17px' });
            }

            $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", })
            var ModuleID = Y.getUrlParam("ModuleID");

            //****************************注: PLItemPricePeriodArea和PLItemPricePeriod两个文件的步骤分两个页面 2017-4-27

            calcContainer();
            $(window).resize(function () {
                //重新计算容器高度
                calcContainer();
            })


            $('#search-date').datepicker({
                format: "yyyy-mm",
                startView: 1,
                minViewMode: 1,
                language: "zh-CN",
                autoclose: true
            });

            Y.API2('PLBasSalePlan', 'GetWeekByYearAndMonth', {}, function (data) {
                if (!Y.checkNull(data) && data.Success != false) {
                    $.each(data, function (i, item) {
                        $('#search-date').val(item.Yearv + "-" + item.Monthv);
                        $('#search-date').datepicker("update");
                        loadList();
                    });
                }

            });
            //处理表格兼容
            var sUserAgent = navigator.userAgent.toLowerCase();
            if (sUserAgent.indexOf('chrome') == -1) {
                $('.tb-head-container').css({ 'paddingRight': '17px' });

            }
            //绑定数据



            var fieldname = "商品层";
            $(".Dimension").on("ifChanged", function () {
                fieldname = $(this).attr("data-fieldname");
            });

            function initThead() {
                //初始化表头（步骤1）
                tableControl.initThead('.tb-head-container .loadTable', [{
                    trClass: '', children: [
                        //{ tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllPlan" />', tdId: '', tdClass: '' },
                        { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:200px;">年-月</span>', tdId: '', tdClass: 'diy-td-w200' },
                        { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:200px;">区域</span>', tdId: '', tdClass: 'diy-td-w200' },

                        { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:200px;">' + fieldname + '</span>', tdId: '', tdClass: 'diy-td-w200' },

                        { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:200px;">占比(%)</span>', tdId: '', tdClass: 'diy-td-w200' },
                    ]
                }]);
            }
            initThead();

            //查询
            $(document).on("click", "#btn-search", function () {
                initThead();
                loadList();
            });



            var page = 1;
            var pageList = [];
            //步骤1 绑定数据
            function loadList() {
              
                var Dimension = $("input[name='Dimension']:checked").val();
                var Yearv = $('#search-date').datepicker("getDate").getFullYear();
                var Monthv = $('#search-date').datepicker("getDate").getMonth();
                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('PLParentRate', 'GetPLParentRateList', {
                    Dimension: Dimension,
                    Yearv: Yearv,
                    Monthv: Monthv + 1
                }, function (data) {
                    layer.closeAll('dialog');
                    $('.tb-body-container .loadTable tbody').html("");
                    var allLength = data.length;
                    var tempList = [];
                    var queryResult = $.Enumerable.From(data).GroupBy("$=>{Yearv:$.Yearv,Monthv:$.Monthv,ParentAreaID:$.ParentAreaID}", null,
                    "{Yearv:$.Yearv,Monthv:$.Monthv,ParentAreaID:$.ParentAreaID}"
                    , "$.Yearv + '-'+ $.Monthv + '-'+ $.ParentAreaID").ForEach(function (x, index) {
                        var tt = [];
                        tempList[index] = [];
                        var g = $.Enumerable.From(data).Where(function (f, j) {
                            //  console.log(eval(whereField));
                            return f.Yearv == x.Yearv && f.Monthv == x.Monthv && f.ParentAreaID == x.ParentAreaID;
                        }).ForEach(function (y, j) {
                            tempList[index][j] = y;
                         
                        });
                      
                    });// 分组结果
                    data = tempList;
                    var tBody = [];
                    if (!Y.checkNull(data)) {
                      
                        if (data.length > 0) {
                            data.map(function (item, i) {

                                item.map(function (item2, j) {
                                    var tempChild = [];

                                    //  { tdText: '', c: 0, r: item.length, tdHtml: '<input type="checkbox" class="checkPlan" />', tdId: '', tdClass: '' },
                                    if (i == 0&&j==0)
                                        tempChild.push({ tdText: '', c: 0, r: allLength, tdHtml: '<span style="display:inline-block; width:200px;">' + (item2.Yearv + '-' + item2.Monthv) + '</span>', tdId: '', tdClass: 'diy-td-w200 border-bottom-bold' });
                                    if (j == 0) {
                                     
                                        tempChild.push({ tdText: '', c: 0, r: item.length, tdHtml: '<span style="display:inline-block; width:200px;">' + (item2.ParentAreaID || ' ') + '</span>', tdId: '', tdClass: 'diy-td-w200 border-bottom-bold' });
                                    }
                                    tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:200px;">' + (item2.ModelName || ' ') + '</span>', tdId: '', tdClass: 'diy-td-w200 ' + (j == item.length - 1 ? "border-bottom-bold" : "") });
                                    tempChild.push({ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:200px;">' + (item2.MatToParentRate || '0') + '</span>', tdId: '', tdClass: 'diy-td-w200 ' + (j == item.length - 1 ? "border-bottom-bold" : "") });

                                    var tempTr = {
                                        trClass: (i % 2 == 0 ? 'gradeX  ' : 'gradeX  '),
                                        children: tempChild
                                    };
                                    tBody.push(tempTr);

                                });

                            });
                            

                            //  return false;
                        }
                        tableControl.initTbody('.loadTable', (tBody.length > 0 ? tBody : null), 0, null);
                    } else {

                        var thc = $(".tb-head-container");
                        $('.tb-body-container .loadTable').append(
              '<tr><td style="width:' + thc.find('th:first').width() + 'px;"><i class="fa fa-frown-o"></i></td>' +
              '<td style="width:' + (thc.find('.loadTable').width() - thc.find('th:first').width()) + 'px;">无数据</td></tr>');
                    }



                    calcContainer();
                });

            }



        })

    </script>

</asp:Content>

